<?php

	global $wpdb;
	require_once("packageclass.php");
	$objPack = new packageClass();
	$table_name =  'wp_spec_package';
	$pagename   =  'Package';
	$addme=$_POST["addme"];
	/*if($addme==1)
	{   
	echo 'asdasdasd';
	exit;
		$objPack->addNewPackage($table_name = $table_name,$_POST);
		//header("Location:admin.php?page=myplug/muyplg.php&info=saved");
		//exit;
	}
	else if($addme==2)
	{
		$objPack->updPackage($table_name =  $table_name,$_POST);
		exit;
		//header("Location:admin.php?page=myplug/muyplg.php&info=upd");
		exit;
	}
*/
	$act=$_REQUEST["act"];
	if($act=="upd")
	{
		$recid=$_REQUEST["id"];
		$sSQL="select * from ".$table_name ." where id=$recid";
		$result = mysql_query($sSQL) or die ('Error, query failed');
		if (mysql_num_rows($result) > 0 )
		{
			if($row = mysql_fetch_assoc($result))
			{
				$id        		= $row['id'];
				$name     		= $row['name'];
				$description  	= $row['description'];
				$terms    	    = $row['terms'];
				$link 	        = $row['link'];
				$status      	= $row['status'];
				$price    		= $row['price'];
				$btn	   = "Update".$pagename;
				$hidval	   = 2;
			}
		}
	}
	else
	{
		$btn	     ="Add New".$pagename;
		$id          = "";
		$name  	     = "";
		$description = "";
		$terms       = "";
		$sort_order  = "";
		$price		 = "";
		$hidval	     = 1;

	}
?>
<div class="wrap">

	<div class="icon32" id="icon-edit"><br/></div>
<h2>Add/Edit Package&nbsp;</h2>
<div id="col-center" style="width:900px;">
	<div class="col-wrap">
		<div>
			<div class="form-wrap">
				<h3></h3>
				<form class="validate" action="admin.php?page=package_add" enctype="multipart/form-data" method="post" id="addtag">
                
                
                
                	<div id="titlediv">
                        <div id="titlewrap">
                        		
                            <input type="text" placeholder="Enter Name here" size="40" id="title" name="name" value="<?php echo $name; ?>"/>    
                        </div>
                    </div>
               
					<!--<div class="form-field">
						<label for="tag-name">Name</label>
						<input type="text" size="40" id="name" name="name" value="<?php echo $name; ?>"/>
					</div>-->
<!--                    <div class="form-field">
						<label for="tag-name">Price</label>
						<input type="text" style="width:50px;" size="40" id="price" name="price" value="<?php echo $price; ?>"/>
					</div>-->
                    <div class="inside">
						<div id="edit-slug-box" class="hide-if-no-js"></div>
					</div>
                    <div id="titlediv">
                        <div id="titlewrap">
                        		
                            <input type="text" size="40"  placeholder="Price" style="width:100px;" id="title" name="price" value="<?php echo $price; ?>"/>    
                        </div>
                    </div>
					 <div class="form-field">
                    	<h3>Description</h3>
					
						<!--<textarea id="terms" name="terms"  rows="5"><?php echo $terms; ?></textarea>-->
                        <?php
					   		$settings = array( 'media_buttons' => false,'textarea_rows' => 7 );
							$content = $terms;
							$editor_id = 'terms';
							wp_editor( $content, $editor_id,$settings);
							?>
     			   </div>
                    <div class="form-field">
						<h3>Terms</h3>
						<!--<textarea id="description" name="description" rows="5" ><?php echo $description; ?></textarea>-->
                       <?php
					   		$settings = array( 'media_buttons' => false,'textarea_rows' => 7 );
							$content = $description;
							$editor_id = 'description';
							wp_editor( $content, $editor_id,$settings);
							?>
					
					</div>
                   
                    
                     <div class="form-field">
						<label for="tag-name">Sample Link</label>

						<input type="text" size="40" id="link" name="link" value="<?php echo $sort_order; ?>"/>
					</div>
			  <p class="submit">
						<input type="submit" value="<?php echo $btn; ?>" class="button button-primary" id="submit" name="submit_package"/>
                        <input type="hidden" name="type" value="Package" />
						<input type="hidden" name="id" value=<?php echo $id;?> >
                       	<input type="hidden" name="addme" value=<?php echo $hidval;?> >
					</p>
				</form>
			</div>
		</div>
	</div>
</div>
</div>
<script>
jQuery( "#toplevel_page_myplug-muyplg" ).removeClass();
jQuery( "#toplevel_page_myplug-muyplg" ).addClass( "wp-has-submenu wp-has-current-submenu wp-menu-open menu-top menu-icon-generic toplevel_page_myplug/muyplg" );
jQuery("#toplevel_page_myplug-muyplg").css("background-color", "#0074a2");
</script>

